<?php
/*namespace Home\Controller;
use Think\Controller;
class HallController extends Controller{
	public function title(){
		$suId=session('user_id');
		$this->assign('session',md5($suId));
		$uCont=M('user')->where("user_id=$suId")->field(array('user_id','user_name','user_img','user_linvite','user_text'))->find();
		$this->assign('uCont',$uCont);
		$messCont=M('mess')->where("accepe_user_id=$suId and mess_pass=0")->select();
		foreach($messCont as $m){
			$userContMess=M('user')->where("user_id=$m[send_user_id]")->field(array('user_id','user_name','user_img'))->find();
			$articleMess=M('article')->where("article_id=$m[article_id]")->field('article_id','article_title','article_content')->find();
			$arrMess[]=array(
			'uMid'=>$m['send_user_id'],
			'uMname'=>$userContMess['user_name'],
			'uMimg'=>$userContMess['user_img'],
			'aMid'=>$m['article_id'],
			'aMtitle'=>$articleMess['article_title'],
			'aMcontent'=>htmlspecialchars_decode(substr($articleMess['article_content'],1,150)),
			'Mid'=>$m['mess_id'],
			'MessContent'=>$m['mess_content'],
			'MessType'=>$m['mess_type'],
			'MessTime'=>date("Y-m-d H:i:s",$m['mess_time']),
			);
			}
		  $messNum=M('mess')->where("accepe_user_id=$suId and mess_pass=0")->Count();
		 $messNum=$messNum!=0?$messNum:'';
		 $this->assign('messNum',$messNum);
		 $this->assign('messList',$arrMess);	
		}
	public function MessSeek(){//这是消息找你的方法
		if(IS_AJAX){
			$userId=session('user_id');
			$userHe=I('umid','','int');
			$amId=I('amid','','int');
			$mid=I('mid','','int');
		    $mtype=I('mtype','','int');
			switch($mtype){
				case 3:$type=2;$messType=6;$articleClass='article_discuss';$userIn=$userHe;$userSuccess='user_discuss';break;//这是文章
				case 4:$type=1;$messType=7;$articleClass='article_marking';$userIn=$userHe;$userSuccess='user_marking';break;//这是文章申请批阅
				case 5:$type=2;$messType=8;$articleClass='article_discuss';$userIn=$userId;$userSuccess='user_discuss';break;
				default :exit;
				}
				  $artMess=M('article')->where("article_id=$amId and article_type=$type")->getField($articleClass);
					  $arrDiscuss=explode('@',$artMess);
					  if(in_array($userIn,$arrDiscuss)){
						$messPass=M('mess')->where("mess_id=$mid and send_user_id=$userHe and accepe_user_id=$userId")->setField('mess_pass','1');
						$messCont=M('mess')->where("accepe_user_id=$userId and mess_pass=0")->Count();
						echo "$messCont";
						exit;
					  }
					  $artMess=$artMess?$artMess.'@'.$userIn:$userIn;
					 $aetSet=M('article')->where("article_id=$amId and article_type=$type and article_user_id=$userId")->setField($articleClass,$artMess);
					 if(!$userHe)exit;
					 $success=M('user')->where("user_id=$userIn")->getField($userSuccess);
					 $success=$success?$success.'@'.$amId:$amId;
					 M('user')->where("user_id=$userIn")->setField($userSuccess,$success);
					 $messPass=M('mess')->where("mess_id=$mid and send_user_id=$userHe and accepe_user_id=$userId")->setField('mess_pass','1');
					 $dataMess=array(
						'article_id'=>$amId,
						'mess_type'=>$messType,
						'send_user_id'=>$userId,
						'accepe_user_id'=>$userHe,
						'mess_time'=>time()
						);
					M('mess')->data($dataMess)->add();
					$messCont=M('mess')->where("accepe_user_id=$userId and mess_pass=0")->Count();
					echo "$messCont";
				   
			}else{
				$this->error('非法访问');
				}
		}
	public function MessIgnore(){//这是消息忽略
		$userId=session('user_id');
	    $mid=I('mid','','int');
		$mtype=I('mtype','','int');	
		 $messPass=M('mess')->where("mess_id=$mid and accepe_user_id=$userId")->setField('mess_pass','2');
		$messCont=M('mess')->where("accepe_user_id=$userId and mess_pass=0")->Count();
		$messCont=$messCont!=0?$messCont:'';
					echo "$messCont";
		}
	public function messRead(){
		$userId=session('user_id');
		$type=I('type','','int');
		if($type==1){
			$where['mess_type']=array('in','1,2');
			$where['accepe_user_id']=array('eq',$userId);
			$messPass=M('mess')->where($where)->setField('mess_pass','1');
			}elseif($type==2){
			$where['mess_type']=array('in','6,7,8');
			$where['accepe_user_id']=array('eq',$userId);
			$messPass=M('mess')->where($where)->setField('mess_pass','1');
			}
		$messCont=M('mess')->where("accepe_user_id=$userId and mess_pass=0")->Count();
		$messCont=$messCont!=0?$messCont:'';
		echo "$messCont";
		}
		public function myTag($uid){
		$xqTagId=M('user_tag')->where("user_id=$uid and tag_type=1")->getField("tag_id",true);
		$scTagId=M('user_tag')->where("user_id=$uid and tag_type=2")->getField("tag_id",true);
		$xqmap['tag_id']=array('in',$xqTagId);
		$scmap['tag_id']=array('in',$scTagId);
		$xqTag=M('tag')->where($xqmap)->select();
		$scTag=M('tag')->where($scmap)->select();
		$this->assign('xqTag',$xqTag);
		$this->assign('scTag',$scTag);
		}
	public function hall(){
	    $userId=session('user_id');
		$this->assign('session','');
		if(IS_POST){
			$arrTag=I('tag','','htmlspecialchars');
			$mapTag['tag_id']=array('in',$arrTag);
			$arrUser=M('user_tag')->where($mapTag)->getField('user_id',true);
			$arrUser=array_flip(array_flip($arrUser));
			$mapArticle['article_user_id']=array('in',$arrUser);
			$mapArticle['article_father_id']=array('eq','0');
			$article=D('article')->relation(true)->where($mapArticle)->order('article_id desc')->select();
			foreach($article as $a){
				$article_zan=$a['article_zan'];
				$article_zan_id=$a['article_zan_id'];
				$article_dao=$a['article_dao'];
				$article_dao_id=$a['article_dao_id'];
				$arrZan=explode("@",$article_zan_id);
				$article_zan_id=in_array($userId,$arrZan)?1:0;
				$arrDao=explode("@",$article_dao_id);
				$article_dao_id=in_array($userId,$arrDao)?1:0;
				$arrOrder=explode("@",$a['article_order']);
				$is_order=in_array($userId,$arrOrder)?1:0;
				$order=$a['article_order']?count($arrOrder):0;
 
				$arrCont[]=array('article_id'=>$a['article_id'],'article_father_id'=>$a['article_father_id'],'article_title'=>$a['article_title'],'article_content'=>htmlspecialchars_decode($a['article_content']),'article_type'=>$a['article_type'],'article_time'=>$a['article_time'],'father_id'=>$a['article_father_id'],'article_order'=>$order,'is_order'=>$is_order,'article_zan'=>$article_zan,'article_zan_id'=>$article_zan_id,'article_dao'=>$article_dao,'article_dao_id'=>$article_dao_id,'user_id'=>$a['user_id'],'user_email'=>$a['user_email'],'user_img'=>$a['user_img'],'user_name'=>$a['user_name']);
				}
			$tagName=M('tag')->where($mapTag)->getField('tag_content',true);
			$this->assign('tagName',$tagName);
			$this->assign('list',$arrCont);	
			}else{
			$mapArticle['article_father_id']=array('eq','0');
		    $article=D('article')->relation(true)->where($mapArticle)->order('article_id desc')->select();
			
				foreach($article as $a){
				$article_zan=$a['article_zan'];
				$article_zan_id=$a['article_zan_id'];
				$article_dao=$a['article_dao'];
				$article_dao_id=$a['article_dao_id'];
				$arrZan=explode("@",$article_zan_id);
				$article_zan_id=in_array($userId,$arrZan)?1:0;
				$arrDao=explode("@",$article_dao_id);
				$article_dao_id=in_array($userId,$arrDao)?1:0;
				$arrOrder=explode("@",$a['article_order']);
				$is_order=in_array($userId,$arrOrder)?1:0;
				$order=$a['article_order']?count($arrOrder):0;
 
				$arrCont[]=array('article_id'=>$a['article_id'],'article_father_id'=>$a['article_father_id'],'article_title'=>$a['article_title'],'article_content'=>htmlspecialchars_decode($a['article_content']),'article_type'=>$a['article_type'],'article_time'=>$a['article_time'],'father_id'=>$a['article_father_id'],'article_order'=>$order,'is_order'=>$is_order,'article_zan'=>$article_zan,'article_zan_id'=>$article_zan_id,'article_dao'=>$article_dao,'article_dao_id'=>$article_dao_id,'user_id'=>$a['user_id'],'user_email'=>$a['user_email'],'user_img'=>$a['user_img'],'user_name'=>$a['user_name']);
				}
			$this->assign('list',$arrCont);	
				}
        $tagParent=M('tag')->select();
		$arr=array();
	    function  tagLayer($cate,$pid=0){
			foreach($cate as $v){
				if($v['tag_parent_id']==$pid){
					$v['cate']=tagLayer($cate,$v['tag_id']);      
					$arr[]=$v;
					}
				}
				return $arr;
		}
		$tagList=tagLayer($tagParent);
		$this->assign('tag',$tagList);
		$this->title();
		$this->display();
	}
		
	}*/
?>